<?php
class Comment extends AModel
{
    public function __construct($in_args=array())
	{
		// This type of object is revision lockable
		$this->table = 'comments';

		$this->verifyArguments($in_args);

		$this->import($in_args);
	}

	public function getFormattedBody()
	{
		$no_windows_newlines = str_replace("\r", "", $this->get('body'));
		$html_newlines = str_replace("\n", "</p><p>\n", $no_windows_newlines);
		$html_newlines = strip_tags($html_newlines, '<a><p><strong><em>');
		$html_newlines = str_replace('<a ', '<a rel="nofollow" ', $html_newlines);
		return "<p>" . $html_newlines . "</p>\n";
	}

	private function verifyArguments(&$in_args)
	{
		$errors = false;

		if ($errors)
			$this->invalidArguments(__CLASS__);
	}

	public function asRSS()
	{
		$fields = array(
		'title' => '<![CDATA[' . $this->get('name') . ']]>',
		'link' => "http://" . $_SERVER['SERVER_NAME'] . "/blog/post/" . $this->getId(),
		'description' =>  '<![CDATA[' . substr(strip_tags($this->getFormattedBody()),0,100) . '[...]' . ']]>',
		'content:encoded' => '<![CDATA[' . $this->getFormattedBody() . ']]>',
		'pubDate' => date('r', $this->get('date_added'))
		);

		return $this->asXML($fields, true);
	}

}
?>